/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number[]}
 */
var intersection = function (nums1, nums2) {
  let shortArr = nums1.length > nums2.length ? nums2 : nums1
  let longArr = nums1.length > nums2.length ? nums1 : nums2
  let result = []
  for (let i in longArr) {
    if (shortArr.indexOf(longArr[i]) > -1) {
      if (result.indexOf(longArr[i]) < 0) {
        result.push(longArr[i])
      }
    }
  }
  return result
};
let nums1 = [1, 2, 2, 1]
let nums2 = [2]
nums1 = [4, 9, 5]
nums2 = [9, 4, 9, 8, 4]
console.log(intersection(nums1, nums2))
